﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Common.BLL;
using Yipusoft.Account.BLL;
using Yipusoft.ProfessionalTeam.DAL;
using Yipusoft.BasicBase.Model;
using Yipusoft.Common.Model;
using Yipusoft.BasicBase.BLL;
using Yipusoft.SoldierArchives.BLL;
using Yipusoft.SoldierArchives.Model;
using Yipusoft.Vehicle.Model;
using Yipusoft.Vehicle.BLL;

public partial class MapInfo_ProfessionalTeam_HelpNew : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.UrlReferrer != null)
            {
                ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
            }
            //专业队伍车辆显示
            if (Request["Pid"] != null)
            {
                LinkButton1.Visible = true;
                GridView1.Visible = true;
                BindList();
            }
            else
            {
                LinkButton1.Visible = false;
                GridView1.Visible = false;
            }
            init();

            ListPageContral2.PageSizeChange += new PageSizeChangeEventHandler(ListPageContral2_PageSizeChange);
        }
    }

    protected void ListPageContral2_PageSizeChange(int pageSize, int PageIndex)
    {
        BindSoldiers(PageIndex);
    }

    public void init()
    {
        BindSoldiers(0);

        BindAllDeviceds(0);
        BindCardre();
    }

    public void BindCardre()
    {
        string DepartmentId = Request["DepartmentId"];
        List<Yipusoft.MapInfo.Model.SoldierArchiveInfo> list = new Yipusoft.MapInfo.BLL.Cadre().GetSoldiersByWhere(" DepartmentID='" + DepartmentId + "'");
        cblCadre.DataSource = list;
        cblCadre.DataBind();

        TeamDataContext tdc = new TeamDataContext();
        Guid parentId = Guid.NewGuid();
        string Type = Request["Type"];
        if (Type == "1")
        {
            parentId = new Guid(Request["Pid"]);
        }
        else if (Type == "2")
        {
            parentId = new Guid(Request["Aid"]);
        }
        List<ProTeamCadre> cadres = tdc.ProTeamCadre.Where(o => o.ParentId.Value == parentId).ToList();
        for (int i = 0; i < cblCadre.Items.Count; i++)
        {
            Guid CadreId = new Guid(cblCadre.Items[i].Value);
            ProTeamCadre cadre = cadres.Where(o => o.CadreId == CadreId).FirstOrDefault();
            if (cadre != null)
            {
                cblCadre.Items[i].Selected = true;
            }
            else
            {
                cblCadre.Items[i].Selected = false;
            }
        }
        List<Guid> cadreIds = (from o in cadres select o.CadreId.Value).ToList();
        var aa = (from o in list where cadreIds.Contains(new Guid(o.CadreID)) select o).ToList();
        CadreDL.DataSource = aa;
        CadreDL.DataBind();

    }

    private void BindSoldiers(int PageIndex)
    {
        List<string> noStandDevices = new List<string>();
        List<string> noStandVehicles = new List<string>();
        TeamDataContext tdc = new TeamDataContext();
        string Type = Request["Type"];
        string DepartmentId = Request["DepartmentId"];
        if (Type == "0")
        {
            ListPageContral2.ItemCount = tdc.vw_HealpSodliers.Where(o => o.DepartmentID == DepartmentId).Count();
            //---------------人员-----------------------------------------------------------
            List<vw_HealpSodliers> sodlier = tdc.vw_HealpSodliers.Where(o => o.DepartmentID == DepartmentId).Skip(ListPageContral2.PageSize * PageIndex).Take(ListPageContral2.PageSize).ToList<vw_HealpSodliers>();
            gvSoldiers.DataSource = sodlier;
            gvSoldiers.DataBind();
            //--------------名称------------
            lblHelpName.Text = "抢险救援班";

            if (Yipusoft.ProfessionalTeam.BLL.Stat.isComplianceHelpByDepartment(DepartmentId, out noStandDevices))
            {
                isStandard.Text = "√";
                isStandard.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                isStandard.Text = "×";
		//Response.Write("1");
                isStandard.ForeColor = System.Drawing.Color.Red;
            }
            hypViewStandard.NavigateUrl = "抢险救援班标准.doc";
        }
        else if (Type == "1")
        {
            Guid pid = new Guid(Request["Pid"]);
            ListPageContral2.ItemCount = tdc.vw_ProsSoldiers.Where(o => o.Pid == pid).Count();
            List<vw_ProsSoldiers> sodier = tdc.vw_ProsSoldiers.Where(o => o.Pid == pid).Skip(ListPageContral2.PageSize * PageIndex).Take(ListPageContral2.PageSize).ToList<vw_ProsSoldiers>();
            gvSoldiers.DataSource = sodier;
            gvSoldiers.DataBind();
            //--------------名称------------
            ProfessionalProc proc = tdc.ProfessionalProc.Where(o => o.id == pid).FirstOrDefault();
            ProcsType type = tdc.ProcsType.Where(o => o.Id == proc.ProcessionType).FirstOrDefault();
            lblHelpName.Text = type.TypeName;


            if (Yipusoft.ProfessionalTeam.BLL.Stat.isComplianceProsByPid(pid, out noStandDevices, out noStandVehicles))
            {
                isStandard.Text = "√";
                isStandard.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                isStandard.Text = "×";
		//Response.Write("2");
                isStandard.ForeColor = System.Drawing.Color.Red;
            }
            hypViewStandard.NavigateUrl = "专业队伍建设标准.doc";
        }
        else if (Type == "2")
        {
            Guid Aid = new Guid(Request["Aid"]);
            //---------------人员-----------------------------------------------------------
            ListPageContral2.ItemCount = tdc.vw_AssaultSoldiers.Where(o => o.AId == Aid).Count();
            List<vw_AssaultSoldiers> sodlier = tdc.vw_AssaultSoldiers.Where(o => o.AId == Aid).Skip(ListPageContral2.PageSize * PageIndex).Take(ListPageContral2.PageSize).ToList<vw_AssaultSoldiers>();
            gvSoldiers.DataSource = sodlier;
            gvSoldiers.DataBind();
            //--------------名称------------
            Assault assault = tdc.Assault.Where(o => o.Id == Aid).FirstOrDefault();
            AssaultType type = tdc.AssaultType.Where(o => o.Id == assault.TypeId).FirstOrDefault();
            lblHelpName.Text = type.TypeName;


            if (Yipusoft.ProfessionalTeam.BLL.Stat.isComplianceAssaultByPid(Aid, out noStandDevices))
            {
                isStandard.Text = "√";
                isStandard.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                isStandard.Text = "×";
		//Response.Write("3");
		//Response.Write(Aid.ToString());
                isStandard.ForeColor = System.Drawing.Color.Red;
            }
            hypViewStandard.NavigateUrl = "攻坚组装备配备标准.doc";
            BindCardre();
        }
        if (Type == "2")
        {
            tbCadre.Visible = false;
            tbCadreView.Visible = true;
            DivCadre.Visible = true;
            gvSoldiers.Columns[7].Visible = true;
        }
        else
        {
            DivCadre.Visible = false;
            gvSoldiers.Columns[7].Visible = false;
        }
        lblDepartment.Text = Yipusoft.Account.BLL.Department.GetDepartment(DepartmentId).ShortName;

        if (noStandDevices.Count > 0)
        {
            divNostandDevic.Visible = true;
            string NoStandDevicesId = "";
            foreach (string deviceid in noStandDevices)
            {
                NoStandDevicesId += NoStandDevicesId == "" ? "" : ",";
                NoStandDevicesId += "'" + deviceid + "'";

            }

            List<CodeItemInfo> ItmeInfos = CodeItem.GetList(" ItemID in(" + NoStandDevicesId + ") ");
            List<string> aa = (from o in ItmeInfos select o.ItemName).ToList();
            lbNoStandDevices.Text = "";
            foreach (string a in aa)
            {
                lbNoStandDevices.Text += lbNoStandDevices.Text == "" ? "" : "&nbsp;&nbsp;&nbsp;&nbsp;";
                lbNoStandDevices.Text += a;
            }
        }
        else
        {
            divNostandDevic.Visible = false;
        }

        if (noStandVehicles.Count > 0)
        {
            divNostandVehicle.Visible = true;
            string NoStandVehiclesId = "";
            foreach (string deviceid in noStandVehicles)
            {
                NoStandVehiclesId += NoStandVehiclesId == "" ? "" : ",";
                NoStandVehiclesId += "'" + deviceid + "'";

            }

            List<CodeItemInfo> ItmeInfos = CodeItem.GetList2(" groupid='XFZBLB' and  ItemID in(" + NoStandVehiclesId + ") ");
            List<string> aa = (from o in ItmeInfos select o.ItemName).ToList();
            lbNoStandVehicle.Text = "";
            foreach (string a in aa)
            {
                lbNoStandVehicle.Text += lbNoStandVehicle.Text == "" ? "" : "&nbsp;&nbsp;&nbsp;&nbsp;";
                lbNoStandVehicle.Text += a;
            }
        }
        else
        {
            divNostandVehicle.Visible = false;
        }
    }

    protected void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        BindAllDeviceds(PageIndex);
    }

    void BindAllDeviceds(int PageIndex)
    {
        string Type = Request["Type"];
        string DepartmentId = Request["DepartmentId"];
        TeamDataContext tdc = new TeamDataContext();
        if (Type == "0")
        {
            ListPageContral1.ItemCount = tdc.HelpDevices.Where(o => o.DepartmentId == DepartmentId).Count();
            List<HelpDevices> list = tdc.HelpDevices.Where(o => o.DepartmentId == DepartmentId).Skip<HelpDevices>(PageIndex * ListPageContral1.PageSize).Take(ListPageContral1.PageSize).ToList<HelpDevices>();
            gv.DataSource = list;
            gv.DataBind();

        }
        else if (Type == "1")
        {
            Guid Pid = new Guid(Request["Pid"]);
            ListPageContral1.ItemCount = tdc.ProsDevices.Where(o => o.Pid == Pid).Count();
            List<ProsDevices> list = tdc.ProsDevices.Where(o => o.Pid == Pid).Skip<ProsDevices>(PageIndex * ListPageContral1.PageSize).Take(ListPageContral1.PageSize).ToList<ProsDevices>();
            gv.DataSource = list;
            gv.DataBind();
        }
        else if (Type == "2")
        {
            Guid Aid = new Guid(Request["Aid"]);
            ListPageContral1.ItemCount = tdc.AssaultDevices.Where(o => o.AId == Aid).Count();
            List<AssaultDevices> list = tdc.AssaultDevices.Where(o => o.AId == Aid).Skip<AssaultDevices>(PageIndex * ListPageContral1.PageSize).Take(ListPageContral1.PageSize).ToList<AssaultDevices>();
            gv.DataSource = list;
            gv.DataBind();
        }
    }

    public string GetType(string deviceClass)
    {
        Yipusoft.Common.Model.CodeItemInfo info = CodeItem.GetCodeItem(deviceClass);
        if (info != null)
        {
            if (info.ItemLevel == 2)
            {
                return CodeItem.GetCodeItem(info.ParentID).ItemName;
            }
            else
            {
                return info.ItemName;
            }
        }
        else
        {
            return "";
        }
    }

    protected string GetDepartmentName(string data)
    {
        if (data != "")
        {
            return Department.GetDepartment(data).FullName;
        }
        else
        {
            return "";
        }
    }

    public string GetCodeItem(string deviceClass)
    {
        Yipusoft.Common.Model.CodeItemInfo info = CodeItem.GetCodeItem(deviceClass);
        return info != null ? info.ItemName : "";
    }
    protected void gvSoldiers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            System.Web.UI.HtmlControls.HtmlAnchor AName = e.Row.FindControl("AName") as System.Web.UI.HtmlControls.HtmlAnchor;
            Label lblId = e.Row.FindControl("lblId") as Label;
            Soldier soldierOp = new Soldier();
            SoldierArchiveInfo soldier = soldierOp.GetSoldierInfoByID(lblId.Text);
            AName.InnerText = soldier.SoldierName;
            //ImageButton btnEdit = e.Row.FindControl("btnEdit") as ImageButton;
            if (soldier.IsContract)
            {
                //AName.HRef = "javascript:OpenWin('EmployeeView.aspx?ID=" + soldier.SoldierID + "')";

                AName.HRef = "../../BasicBase/SoldierArchive/EmployeeView.aspx?ID=" + soldier.SoldierID;
                // btnEdit.PostBackUrl = "NewEmployee.aspx?ID=" + soldier.SoldierID;
            }
            else
            {
                //AName.HRef = "javascript:OpenWin('SoldierView1.aspx?ID=" + soldier.SoldierID + "')";
                AName.HRef = "../../BasicBase/SoldierArchive/SoldierView1.aspx?ID=" + soldier.SoldierID;
                //btnEdit.PostBackUrl = "NewSoldier.aspx?ID=" + soldier.SoldierID;
            }
            if (gvSoldiers.Columns[7].Visible == true)
            {
                HyperLink hyViewGrade = e.Row.FindControl("hyViewGrade") as HyperLink;
                hyViewGrade.NavigateUrl = "ViewProsGrade.aspx?IsCadre=0&PersonId=" + soldier.SoldierID + "&DepartmentId=" + Request["DepartmentId"];
            }
            LinkButton lkbAddGrade = e.Row.FindControl("lkbAddGrade") as LinkButton;
            if (Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0, 4) == "1300")
            {
                lkbAddGrade.Visible = true;
            }
            else
            {
                lkbAddGrade.Visible = false;
            }
            TeamDataContext tdc = new TeamDataContext();
            ProsGrade grade = tdc.ProsGrade.Where(o => o.IsCadre == 0 && o.personId == new Guid(soldier.SoldierID)).FirstOrDefault();
            if (grade != null)
            {
                decimal SumSore = grade.FWCScore + grade.YWQZScore + grade.DGScore + grade.SGScore + grade.Run5000Score + grade.Run5000FScore + grade.Run100FScore + grade.TheoryScore;
                Label lblSorce = e.Row.FindControl("lblSorce") as Label;
                lblSorce.Text = SumSore.ToString("0.00");
                if (SumSore >= 60)
                {
                    lblSorce.ForeColor = System.Drawing.Color.Blue;
                }
                else
                {
                    lblSorce.ForeColor = System.Drawing.Color.Red;
                }
            }
        }
    }

    protected void gvDevices_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Request["Pid"] != null)
        {
            Response.Redirect("SodiersNew.aspx?DepartmentId=" + Request["DepartmentId"] + "&Type=" + Request["Type"] + "&Pid=" + Request["Pid"]);
        }
        else if (Request["Aid"] != null)
        {
            Response.Redirect("SodiersNew.aspx?DepartmentId=" + Request["DepartmentId"] + "&Type=" + Request["Type"] + "&Aid=" + Request["Aid"]);
        }
        else
        {
            Response.Redirect("SodiersNew.aspx?DepartmentId=" + Request["DepartmentId"] + "&Type=" + Request["Type"] + "");
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (Request["Pid"] != null)
        {
            Response.Redirect("DeviceNew.aspx?DepartmentId=" + Request["DepartmentId"] + "&Type=" + Request["Type"] + "&Pid=" + Request["Pid"]);
        }
        else if (Request["Aid"] != null)
        {
            Response.Redirect("DeviceNew.aspx?DepartmentId=" + Request["DepartmentId"] + "&Type=" + Request["Type"] + "&Aid=" + Request["Aid"]);

        }
        else
        {
            Response.Redirect("DeviceNew.aspx?DepartmentId=" + Request["DepartmentId"] + "&Type=" + Request["Type"] + "");
        }
    }
	bool bl=false;
    protected void UserGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = ((ListPageContral1.CurrentPageIndex * ListPageContral1.PageSize) + (e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");

            #region 赋值
            Guid DeviceId = new Guid(gv.DataKeys[e.Row.RowIndex][0].ToString());
            DeviceInfo device = Device.GetDevice(DeviceId);
		 if (device == null&&(!bl))
            {
		bl=true;
                Response.Write("---"+DeviceId);
                return;
            }
            Label DeviceName = e.Row.FindControl("DeviceName") as Label;
		

		           DeviceName.Text = device.DeviceName;
			
            Label DeviceClass = e.Row.FindControl("DeviceClass") as Label;

            CodeItemInfo item = CodeItem.GetCodeItem(device.DeviceClass);
            if (item != null)
            {
                DeviceClass.Text = item.ItemName;
            }
            else
            {
                DeviceClass.Text = "--";
            }
            //DeviceClass.Text = item.ItemName;
            Label State = e.Row.FindControl("State") as Label;
            CodeItemInfo Stateitem = CodeItem.GetCodeItem(device.State);
            if (Stateitem != null)
            {
                State.Text = Stateitem.ItemName;
            }
            else
            {
                State.Text = "--";
            }

            #endregion
        }
    }
    protected void lbtReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect(ViewState["UrlReferrer"].ToString());
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (Request["Pid"] != null)
        {
            Response.Redirect("VehicleNew.aspx?DepartmentId=" + Request["DepartmentId"] + "&Type=" + Request["Type"] + "&Pid=" + Request["Pid"]);
        }
        else
        {
            Response.Redirect("VehicleNew.aspx?DepartmentId=" + Request["DepartmentId"] + "&Type=" + Request["Type"] + "");
        }
    }

    protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");

            #region 赋值
            Guid VehicleId = new Guid(GridView1.DataKeys[e.Row.RowIndex][0].ToString());
            VehicleInfo vehicle = Vehicle.GetDetail(VehicleId);
            Label DeviceName = e.Row.FindControl("DeviceName") as Label;
            DeviceName.Text = vehicle.VehicleName;
            Label DeviceClass = e.Row.FindControl("DeviceClass") as Label;

            CodeItemInfo item = CodeItem.GetCodeItem(vehicle.VehicleClass, "XFZBLB");
            if (item != null)
            {
                DeviceClass.Text = item.ItemName;
            }
            else
            {
                DeviceClass.Text = "--";
            }


            #endregion
        }
    }
    void BindList()
    {

        TeamDataContext tdc = new TeamDataContext();
        Guid pid = new Guid(Request["pid"]);
        List<ProsVehicles> list = tdc.ProsVehicles.Where(o => o.Pid == pid).ToList();
        GridView1.DataSource = list;
        GridView1.DataBind();
    }
    protected void SaveCardre_Click(object sender, EventArgs e)
    {

        TeamDataContext tdc = new TeamDataContext();
        string Type = Request["Type"];
        string DepartmentId = Request["DepartmentId"];
        Guid parentId = Guid.NewGuid();
        if (Type == "1")
        {
            parentId = new Guid(Request["Pid"]);
        }
        else if (Type == "2")
        {
            parentId = new Guid(Request["Aid"]);
        }
        List<ProTeamCadre> cadres = tdc.ProTeamCadre.Where(o => o.ParentId.Value == parentId).ToList();
        tdc.ProTeamCadre.DeleteAllOnSubmit(cadres);
        tdc.SubmitChanges();
        cadres.Clear();
        for (int i = 0; i < cblCadre.Items.Count; i++)
        {
            if (cblCadre.Items[i].Selected)
            {
                ProTeamCadre cadre = new ProTeamCadre();
                cadre.CadreId = new Guid(cblCadre.Items[i].Value);
                cadre.ParentId = parentId;
                cadre.TeamType = Convert.ToInt32(Type);
                cadre.Id = Guid.NewGuid();
                cadres.Add(cadre);
            }
        }
        tdc.ProTeamCadre.InsertAllOnSubmit(cadres);
        tdc.SubmitChanges();
        BindCardre();
        tbCadre.Visible = false;
        tbCadreView.Visible = true;
    }
    protected void gvSoldiers_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string DepartmentId = Request["DepartmentId"];
        if (e.CommandName == "AddGrade")
        {
            Response.Redirect("NewProsGrade.aspx?IsCadre=0&PersonId=" + e.CommandArgument.ToString() + "&DepartmentId=" + DepartmentId);
        }
        else if ((e.CommandName == "lkbViewGrade"))
        {
            Response.Redirect("ViewProsGrade.aspx?IsCadre=0&PersonId=" + e.CommandArgument.ToString() + "&DepartmentId=" + DepartmentId);
        }
    }
    protected void lkbUpdate_Click(object sender, EventArgs e)
    {
        tbCadre.Visible = true;
        tbCadreView.Visible = false;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        tbCadre.Visible = false;
        tbCadreView.Visible = true;
    }
    protected void CadreDL_ItemCommand(object source, DataListCommandEventArgs e)
    {

        string DepartmentId = Request["DepartmentId"];
        if (e.CommandName == "AddGrade")
        {
            Response.Redirect("NewProsGrade.aspx?IsCadre=1&PersonId=" + e.CommandArgument.ToString() + "&DepartmentId=" + DepartmentId);
        }

    }
    protected void CadreDL_ItemDataBound(object sender, DataListItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            LinkButton lkbAddGrade = e.Item.FindControl("lkbAddGrade") as LinkButton;
            if (Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0, 4) == "1300")
            {
                lkbAddGrade.Visible = true;
            }
            else
            {
                lkbAddGrade.Visible = false;
            }
            Yipusoft.MapInfo.Model.SoldierArchiveInfo soldier = e.Item.DataItem as Yipusoft.MapInfo.Model.SoldierArchiveInfo;
            HyperLink hyViewGrade = e.Item.FindControl("hyViewGrade") as HyperLink;
            hyViewGrade.NavigateUrl = "ViewProsGrade.aspx?IsCadre=1&PersonId=" + soldier.CadreID + "&DepartmentId=" + Request["DepartmentId"];
            TeamDataContext tdc = new TeamDataContext();
            ProsGrade grade = tdc.ProsGrade.Where(o => o.IsCadre == 1 && o.personId == new Guid(soldier.CadreID)).FirstOrDefault();
            if (grade != null)
            {
                decimal SumSore = grade.FWCScore + grade.YWQZScore + grade.DGScore + grade.SGScore + grade.Run5000Score + grade.Run5000FScore + grade.Run100FScore + grade.TheoryScore;
                Label lblSorce = e.Item.FindControl("lblSorce") as Label;
                lblSorce.Text = SumSore.ToString("0.00");
                if (SumSore >= 60)
                {
                    lblSorce.ForeColor = System.Drawing.Color.Blue;
                }
                else
                {
                    lblSorce.ForeColor = System.Drawing.Color.Red;
                }
            }
        }
    }
}
